#ifndef ALIEN_ATTACK_TURRET_H
#define ALIEN_ATTACK_TURRET_H

#include "GameObjectFactory.h"
#include "BulletHandler.h"
#include "SoundManager.h"
#include "Enemy.h"
#include <iostream>
#include <cmath>

struct Turret : public Enemy
{
    Turret()
    {
        m_dyingTime = 1000;
        m_health = 15;
        m_bulletFiringSpeed = 50;
    }

    virtual ~Turret() {}

    virtual void collision()
    {
        m_health -= 1;

        if (m_health == 0)
        {
            if (!m_bPlayedDeathSound)
            {
                // TODO: what the fuck is this
                TheSoundManager::Instance()->playSound("explode", 0);

                m_textureID = "largeexplosion";
                m_currentFrame = 0;
                m_numFrames = 9;
                m_width = 60;
                m_height = 60;
                m_bDying = true;
            }
        }
    }

    virtual void update()
    {
        if (!m_bDying)
        {
            // we want to scroll this object with the rest
            scroll(TheGame::Instance()->getScrollSpeed());

            if (m_bulletCounter == m_bulletFiringSpeed)
            {
                TheBulletHandler::Instance()->addEnemyBullet(m_position.getX(), m_position.getY(), 16, 16, "bullet2", 1, Vector2D(-3, -3));
                TheBulletHandler::Instance()->addEnemyBullet(m_position.getX() + 20, m_position.getY(), 16, 16, "bullet2", 1, Vector2D(0, -3));
                TheBulletHandler::Instance()->addEnemyBullet(m_position.getX() + 40, m_position.getY(), 16, 16, "bullet2", 1, Vector2D(3, -3));
                m_bulletCounter = 0;
            }

            m_bulletCounter++;
        }
        else
        {
            scroll(TheGame::Instance()->getScrollSpeed());
            doDyingAnimation();
        }
    }
};

struct TurretCreator : public BaseCreator
{
    GameObject *createGameObject() const
    {
        // TODO: fix this?
        return new Turret();
    }
};

#endif // header file project